<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Column;
use addons\BuilderPlus\facade\Table;
use app\common\model\Assets;

class Transfer extends Base
{
    public function getOptions(): array
    {
        return [
            'pk'    => 'id',
            'model' => \app\common\model\Transfer::class,
            'with'  => ['user', 'take']
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->setCheckbox(false)
            ->addColumns([
                ['id', 'ID', fn(Column $col) => $col->width(80)],
                ['uid', '转账会员', fn(Column $col) => $col->minWidth(250)->templet('#_userTpl')],
                ['take_uid', '收账会员', fn(Column $col) => $col->minWidth(250)->templet('#_takeUserTpl')],
                ['account', '账户'],
                ['amount', '转账金额'],
                ['cost', '转账手续费'],
                ['real_amount', '实际金额'],
                ['create_time', '转账时间', fn(Column $col) => $col->width(140)]
            ])
            ->addSearch([
                ['create_time', '转账时间', fn($s) => $s->type('date')->dateType('datetime')],
                ['uid', '转账会员编号/昵称/手机号', fn($s) => $s->relation('\app\common\model\User', 'code|nickname|mobile,id')],
                ['take_uid', '收账会员编号/昵称/手机号', fn($s) => $s->relation('\app\common\model\User', 'code|nickname|mobile,id')],
                ['account', '账户类型', fn($s) => $s->type('select')->optionValue(Assets::getFields(3))]
            ])
            ->enableExport()
            ->fetch();
    }


}
